package net.starwifi.duobao.dto;

import net.starwifi.duobao.entity.CartItem;

import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Administrator on 2015/11/15.
 */
public class ShopCart {

    private String shopName;

    private Long shopId;

    private Set<CartItem> cartItems = new HashSet<CartItem>();

    private BigDecimal freePostage=BigDecimal.valueOf(10L);

    /**
     * 获取商品价格
     *
     * @return 商品价格
     */
    @Transient
    public BigDecimal getPrice() {
        BigDecimal price = new BigDecimal(0);
        if (getCartItems() != null) {
            for (CartItem cartItem : getCartItems()) {
                if (cartItem != null && cartItem.getSubtotal() != null) {
                    price = price.add(cartItem.getSubtotal());
                }
            }
        }
        return price;
    }


    public String getShopName() {
        return shopName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    public Long getShopId() {
        return shopId;
    }

    public void setShopId(Long shopId) {
        this.shopId = shopId;
    }

    public Set<CartItem> getCartItems() {
        return cartItems;
    }

    public void setCartItems(Set<CartItem> cartItems) {
        this.cartItems = cartItems;
    }

    public BigDecimal getFreePostage() {
        return freePostage;
    }

    public void setFreePostage(BigDecimal freePostage) {
        this.freePostage = freePostage;
    }
}
